package com.alibaba.citrus.cr.mn.order.center.facade.function.convert;

import com.alibaba.citrus.cr.common.enums.ordercenter.OrderCategoryEnum;
import com.alibaba.citrus.cr.common.enums.ordercenter.OrderChannelEnum;
import com.alibaba.citrus.cr.common.enums.ordercenter.StockUnitEnum;
import com.alibaba.citrus.cr.common.util.DateUtils;
import com.alibaba.citrus.cr.mn.order.center.common.util.MoneyUtils;
import com.alibaba.citrus.cr.mn.order.center.common.util.nvlToEmptyUtils;
import com.alibaba.cz.base.tool.log.Log;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.crb2btradecenter.model.dto.LoadOrderDetailListResponse;
import com.epoch.app.crb2btradecenter.obtcsaleorderlineindex.model.ObtcSaleOrderLineIndex;
import com.epoch.app.mnordercenter.model.dto.ExchangeOrderQueryDetailResponse;
import com.epoch.app.mnordercenter.model.dto.PageQuerySaleOrderDetailResponse;
import com.epoch.app.mnordercenter.model.dto.ReturnOrderQueryDetailResponse;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class ObtcSaleOrderLineIndexToResponseConvertor {

	private static final Log log = Log.getLogger(ObtcSaleOrderLineIndexToResponseConvertor.class);

	// 换货明细covent
	public static List<ExchangeOrderQueryDetailResponse> convertExchangeOrderQueryDetailResponse(Result<List<ObtcSaleOrderLineIndex>> listResult) {
		if (Objects.isNull(listResult) || !listResult.isSuccess() || CollectionUtils.isEmpty(listResult.getResult())) {
			return Lists.newArrayList();
		}
		return listResult.getResult().stream()
				.map(ObtcSaleOrderLineIndexToResponseConvertor::convertExchangeOrderQueryDetailResponse)
				.collect(Collectors.toList());
	}

	// 退货明细covent
	public static List<ReturnOrderQueryDetailResponse> convertReturnOrderQueryDetailResponse(Result<List<ObtcSaleOrderLineIndex>> listResult) {
		if (Objects.isNull(listResult) || !listResult.isSuccess() || CollectionUtils.isEmpty(listResult.getResult())) {
			return Lists.newArrayList();
		}
		return listResult.getResult().stream()
				.map(ObtcSaleOrderLineIndexToResponseConvertor::convertReturnOrderQueryDetailResponse)
				.collect(Collectors.toList());
	}

	public static List<PageQuerySaleOrderDetailResponse> convert(Result<List<ObtcSaleOrderLineIndex>> listResult, String orderCategory) {
		if (Objects.isNull(listResult) || !listResult.isSuccess() || CollectionUtils.isEmpty(listResult.getResult())) {
			return Lists.newArrayList();
		}
		if (OrderCategoryEnum.GROUP.getCode().equals(orderCategory)) {
			return listResult.getResult().stream()
					.map(ObtcSaleOrderLineIndexToResponseConvertor::convertF2B)
					.collect(Collectors.toList());
		} else {
			return listResult.getResult().stream()
					.map(ObtcSaleOrderLineIndexToResponseConvertor::convertB2b)
					.collect(Collectors.toList());
		}
	}

	public static List<PageQuerySaleOrderDetailResponse> convert(Result<List<LoadOrderDetailListResponse>> listResult) {
		if (Objects.isNull(listResult) || !listResult.isSuccess() || CollectionUtils.isEmpty(listResult.getResult())) {
			return Lists.newArrayList();
		}
		return listResult.getResult().stream()
				.map(ObtcSaleOrderLineIndexToResponseConvertor::convertPageQuerySaleOrderDetailResponse)
				.collect(Collectors.toList());
	}

	private static PageQuerySaleOrderDetailResponse convertPageQuerySaleOrderDetailResponse(LoadOrderDetailListResponse loadOrderDetailListResponse) {
		return PageQuerySaleOrderDetailResponse.builder()
				.fromSys(nvlToEmptyStr(loadOrderDetailListResponse.getFromSys()))
				.businessType(nvlToEmptyStr(loadOrderDetailListResponse.getBusinessType()))
				.businessUnitCode(nvlToEmptyStr(loadOrderDetailListResponse.getBisUnitOutCode()))
				.businessChannel(nvlToEmptyStr(loadOrderDetailListResponse.getChannelCode()))
				.expectedDeliveryDate(nvlToEmptyStr(loadOrderDetailListResponse.getCustomerExpectDate()))
				.bizFeatures(nvlToEmptyStr(loadOrderDetailListResponse.getBizFeatures()))
				.receiveWarehouseCode(nvlToEmptyStr(loadOrderDetailListResponse.getReceiveWarehouseOutCode()))
				.shippingWarehouseCode(nvlToEmptyStr(loadOrderDetailListResponse.getShippingWarehouseOutCode()))
				.fulfillmentPriority(nvlToEmptyStr(loadOrderDetailListResponse.getFulfillmentPriority()))
				.productGroupCode(nvlToEmptyStr(loadOrderDetailListResponse.getProductGroupCode()))
				.note(nvlToEmptyStr(loadOrderDetailListResponse.getRemark()))
				.salesOrganizationCode(nvlToEmptyStr(loadOrderDetailListResponse.getOrganizationOutCode()))
				.shipToPartyCode(nvlToEmptyStr(loadOrderDetailListResponse.getReceiveAddressCode()))
				.deliveryMethodCode(nvlToEmptyStr(loadOrderDetailListResponse.getTransportModeCode()))
				.customerCode(nvlToEmptyStr(loadOrderDetailListResponse.getCustomerCode()))
				.detailBizFeatures(nvlToEmptyStr(loadOrderDetailListResponse.getSubBizFeatures()))
				.productCode(nvlToEmptyStr(loadOrderDetailListResponse.getScItemOutCode()))
				.productionDate(nvlToEmptyStr(loadOrderDetailListResponse.getProductationTime()))
				.createTime(nvlToEmptyStr(loadOrderDetailListResponse.getGmtCreate()))
				.detailNote(nvlToEmptyStr(loadOrderDetailListResponse.getSubRemark()))
				.salesUnitCode(nvlToEmptyStr(loadOrderDetailListResponse.getSaleUnit()))
				.stockUnitCode(nvlToEmptyStr(loadOrderDetailListResponse.getInventoryUnitCode()))
				.productQuantity(nvlToEmptyStr(loadOrderDetailListResponse.getQuantity()))
				.stockConversionNum(nvlToEmptyStr(loadOrderDetailListResponse.getStockConversionNum()))
				.shippingWarehouseCode(nvlToEmptyStr(loadOrderDetailListResponse.getShippingWarehouseOutCode()))
				.receiveWarehouseCode(nvlToEmptyStr(loadOrderDetailListResponse.getReceiveWarehouseOutCode()))
				.shipToPartyName(nvlToEmptyStr(loadOrderDetailListResponse.getReceiveDetailAddress()))
				.customerName(nvlToEmptyStr(loadOrderDetailListResponse.getCustomerName()))
				.productName(nvlToEmptyStr(loadOrderDetailListResponse.getScItemTitle()))
				.cumulativeNoticeQuantity(nvlToEmptyStr(loadOrderDetailListResponse.getCumulativeNoticeQuantity()))
				.unitConversionRelationship(nvlToEmptyStr(loadOrderDetailListResponse.getUnitConvert()))
				.salesOrderNo(loadOrderDetailListResponse.getOrderBizId())
				.sourceOrderNo(loadOrderDetailListResponse.getSourceOrderNo())
				.lineNum(loadOrderDetailListResponse.getSerialNumber())
				.sourceLineNum(loadOrderDetailListResponse.getSourceLineNum())
				.unitPrice(loadOrderDetailListResponse.getUnitPrice())
				.activityPrice(loadOrderDetailListResponse.getActivityPrice())
				.shippingWarehouseName(loadOrderDetailListResponse.getShippingWarehouseName())
				.receiveWarehouseName(loadOrderDetailListResponse.getReceiveWarehouseName())
				.build();
	}

	private static ExchangeOrderQueryDetailResponse convertExchangeOrderQueryDetailResponse(ObtcSaleOrderLineIndex orderLineIndex) {
		ExchangeOrderQueryDetailResponse.Builder builder = ExchangeOrderQueryDetailResponse.newExchangeOrderQueryDetailResponseBuilder();
		return builder.fromSys(nvlToEmptyStr(orderLineIndex.getMainFromSys()))
				.businessType(String.valueOf(orderLineIndex.getMainBusinessType()))
				.businessTypeName(nvlToEmptyStr(orderLineIndex.getMainBusinessTypeName()))
				.orderCategoryCode(nvlToEmptyStr(orderLineIndex.getMainOrderCategoryCode()))
				.salesOrderNo(orderLineIndex.getMainOrderBizId())
				.sourceOrderNo(orderLineIndex.getMainSourceOrderNo())
				.outOrderNo(orderLineIndex.getMainSourceOrderNo())
				.businessUnitCode(nvlToEmptyStr(orderLineIndex.getMainBisUnitOutCode()))
				.businessUnitName(nvlToEmptyStr(orderLineIndex.getMainBisUnitName()))
				.salesOrderType(nvlToEmptyStr(orderLineIndex.getMainOrderType()))
				.salesOrderTypeName(nvlToEmptyStr(orderLineIndex.getMainOrderTypeName()))
				.productGroupCode(nvlToEmptyStr(orderLineIndex.getMainProductGroupCode()))
				.productGroupName(nvlToEmptyStr(orderLineIndex.getMainProductGroupName()))
				.salesOrganizationCode(nvlToEmptyStr(orderLineIndex.getMainOrganizationOutCode()))
				.salesOrganizationName(nvlToEmptyStr(orderLineIndex.getMainOrganizationName()))
				.customerCode(nvlToEmptyStr(orderLineIndex.getMainCustomerCode()))
				.customerName(nvlToEmptyStr(orderLineIndex.getMainCustomerName()))
				.shipToPartyCode(nvlToEmptyStr(orderLineIndex.getMainReceiveAddressCode()))
				.shipToPartyName(nvlToEmptyStr(orderLineIndex.getMainReceiveDetailAddress()))
				.salesChannelCode(nvlToEmptyStr(orderLineIndex.getMainSaleChannelOutCode()))
				.salesChannelName(nvlToEmptyStr(orderLineIndex.getMainSaleChannelName()))
				.salesDepartmentCode(nvlToEmptyStr(orderLineIndex.getMainDepartmentOutCode()))
				.salesDepartmentName(nvlToEmptyStr(orderLineIndex.getMainDepartmentName()))
				.orderStatus(String.valueOf(orderLineIndex.getMainStatus()))
				.expectedDeliveryDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerExpectDate(),DateUtils.DATE_FORMAT)))
				.deliveryMethodCode(nvlToEmptyStr(orderLineIndex.getMainTransportModeCode()))
				.deliveryMethodName(nvlToEmptyStr(orderLineIndex.getMainTransportModeName()))
				.fulfillmentTypeCode(nvlToEmptyStr(orderLineIndex.getMainFulfillmentTypeCode()))
				.fulfillmentPriority(nvlToEmptyStr(orderLineIndex.getMainFulfillmentPriority()))
				.autoFulfillment(nvlToEmptyStr(orderLineIndex.getMainAutoFulfillment()))
				.orderBizTag(orderLineIndex.getMainOrderBizTag() == null ? Lists.newArrayList() : Lists.newArrayList(orderLineIndex.getMainOrderBizTag().split(",")))
				.creatorCode(nvlToEmptyStr(orderLineIndex.getMainCreatorCode()))
				.creatorName(nvlToEmptyStr(orderLineIndex.getMainCreatorName()))
				.createTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtCreate(), DateUtils.DATETIME_FORMAT)))
				.modifierCode(nvlToEmptyStr(orderLineIndex.getMainModifierCode()))
				.modifierName(nvlToEmptyStr(orderLineIndex.getMainModifierName2()))
				.modifierTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtModified(), DateUtils.DATETIME_FORMAT)))
				.customerPurchaseOrderNo(nvlToEmptyStr(orderLineIndex.getMainCustomerReferenceNo()))
				.customerPurchaseDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerPurchaseDate(),DateUtils.DATE_FORMAT)))
				.bizFeatures(nvlToEmptyStr(orderLineIndex.getMainBizFeatures()))
				.note(nvlToEmptyStr(orderLineIndex.getMainRemark()))
				.lineNum(orderLineIndex.getSubSerialNumber())
				.sourceLineNum(orderLineIndex.getSubSourceLineNum())
				.outLineNum(orderLineIndex.getSubOuterOrderLineId())
				.innerProductCode(nvlToEmptyStr(orderLineIndex.getSubInnerProductCode()))
				.innerProductName(nvlToEmptyStr(orderLineIndex.getSubInnerProductName()))
				.productBarCode(nvlToEmptyStr(orderLineIndex.getSubProductBarCode()))
				.productCode(nvlToEmptyStr(orderLineIndex.getSubScItemOutCode()))
				.productName(nvlToEmptyStr(orderLineIndex.getSubScItemTitle()))
				.salesUnitCode(nvlToEmptyStr(orderLineIndex.getSubSaleUnitCode()))
				.salesUnitName(nvlToEmptyStr(orderLineIndex.getSubSaleUnitName()))
				.stockUnitCode(nvlToEmptyStr(orderLineIndex.getSubInventoryUnitCode()))
				.stockUnitName(nvlToEmptyStr(StockUnitEnum.of(orderLineIndex.getSubInventoryUnitCode()).getDesc()))
				.unitConversionRelationship(nvlToEmptyStr(orderLineIndex.getSubUnitConvert()))
				.unitPrice(StringUtils.isBlank(orderLineIndex.getSubUnitPrice()) ? "" : MoneyUtils.moneyFen2Yuan(Long.valueOf(nvlToEmptyStr(orderLineIndex.getSubUnitPrice()))))
				.totalAmount(StringUtils.isBlank(orderLineIndex.getSubShouldPayFee()) ? "" : MoneyUtils.moneyFen2Yuan(Long.valueOf(nvlToEmptyStr(orderLineIndex.getSubShouldPayFee()))))
				.productionDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getSubProductationTime(), DateUtils.PATTEN_YMD)))
				.productQuantity(nvlToEmptyStr(String.valueOf(orderLineIndex.getSubQuantity())))
				.cumulativeNoticeQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeNoticeQuantity()))
				.cumulativePlanDeliveryQuantity(StringUtils.isBlank(orderLineIndex.getSubCumulativeDeliveryQuantity()) ? 0L : Long.parseLong(orderLineIndex.getSubCumulativeDeliveryQuantity()))
				.closeCode(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonCode()))
				.closeMsg(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonName()))
				.detailStatus(orderLineIndex.getSubStatus().intValue())
				.detailNote(nvlToEmptyStr(orderLineIndex.getSubRemark()))
				.detailBizFeatures(nvlToEmptyStr(orderLineIndex.getSubBizFeatures()))
				.build();
	}

	private static ReturnOrderQueryDetailResponse convertReturnOrderQueryDetailResponse(ObtcSaleOrderLineIndex orderLineIndex) {
		return ReturnOrderQueryDetailResponse.builder()
				.fromSys(nvlToEmptyStr(orderLineIndex.getMainFromSys()))
				.businessType(orderLineIndex.getMainBusinessType())
				.businessTypeName(nvlToEmptyStr(orderLineIndex.getMainBusinessTypeName()))
				.orderCategoryCode(nvlToEmptyStr(orderLineIndex.getMainOrderCategoryCode()))
				.orderCategoryName(OrderCategoryEnum.of(orderLineIndex.getMainOrderCategoryCode()).getDesc())
				.salesOrderNo(orderLineIndex.getMainOrderBizId())
				.sourceOrderNo(orderLineIndex.getMainSourceOrderNo())
				.outOrderNo(orderLineIndex.getMainSourceOrderNo())
				.kaSystem(nvlToEmptyStr(orderLineIndex.getMainKaSystem()))
				.kaArea(nvlToEmptyStr(orderLineIndex.getMainKaArea()))
				.businessUnitCode(nvlToEmptyStr(orderLineIndex.getMainBisUnitOutCode()))
				.businessUnitName(nvlToEmptyStr(orderLineIndex.getMainBisUnitName()))
				.salesOrderType(nvlToEmptyStr(orderLineIndex.getMainOrderType()))
				.salesOrderTypeName(nvlToEmptyStr(orderLineIndex.getMainOrderTypeName()))
				.productGroupCode(nvlToEmptyStr(orderLineIndex.getMainProductGroupCode()))
				.productGroupName(nvlToEmptyStr(orderLineIndex.getMainProductGroupName()))
				.salesOrganizationCode(nvlToEmptyStr(orderLineIndex.getMainOrganizationOutCode()))
				.salesOrganizationName(nvlToEmptyStr(orderLineIndex.getMainOrganizationName()))
				.customerCode(nvlToEmptyStr(orderLineIndex.getMainCustomerCode()))
				.customerName(nvlToEmptyStr(orderLineIndex.getMainCustomerName()))
				.shipToPartyCode(nvlToEmptyStr(orderLineIndex.getMainReceiveAddressCode()))
				.shipToPartyName(nvlToEmptyStr(orderLineIndex.getMainReceiveDetailAddress()))
				.salesChannelCode(nvlToEmptyStr(orderLineIndex.getMainSaleChannelOutCode()))
				.salesChannelName(nvlToEmptyStr(orderLineIndex.getMainSaleChannelName()))
				.salesDepartmentCode(nvlToEmptyStr(orderLineIndex.getMainDepartmentOutCode()))
				.salesDepartmentName(nvlToEmptyStr(orderLineIndex.getMainDepartmentName()))
				.orderStatus(String.valueOf(orderLineIndex.getMainStatus()))
				.expectedDeliveryDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerExpectDate(),DateUtils.DATE_FORMAT)))
				.deliveryMethodCode(nvlToEmptyStr(orderLineIndex.getMainTransportModeCode()))
				.deliveryMethodName(nvlToEmptyStr(orderLineIndex.getMainTransportModeName()))
				.contactor(nvlToEmptyStr(orderLineIndex.getMainContact()))
				.contactPhone(nvlToEmptyStr(orderLineIndex.getMainContactPhone()))
				.fulfillmentTypeCode(nvlToEmptyStr(orderLineIndex.getMainFulfillmentTypeCode()))
				.fulfillmentPriority(nvlToEmptyStr(orderLineIndex.getMainFulfillmentPriority()))
				.autoFulfillment(nvlToEmptyStr(orderLineIndex.getMainAutoFulfillment()))
				.orderBizTag(orderLineIndex.getMainOrderBizTag() == null ? Lists.newArrayList() : Lists.newArrayList(orderLineIndex.getMainOrderBizTag().split(",")))
				.creatorCode(nvlToEmptyStr(orderLineIndex.getMainCreatorCode()))
				.creatorName(nvlToEmptyStr(orderLineIndex.getMainCreatorName()))
				.createTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtCreate(), DateUtils.DATETIME_FORMAT)))
				.modifierCode(nvlToEmptyStr(orderLineIndex.getMainModifierCode()))
				.modifierName(nvlToEmptyStr(orderLineIndex.getMainModifierName2()))
				.modifierTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtModified(), DateUtils.DATETIME_FORMAT)))
				.customerPurchaseOrderNo(nvlToEmptyStr(orderLineIndex.getMainCustomerReferenceNo()))
				.customerPurchaseDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerPurchaseDate(),DateUtils.DATE_FORMAT)))
				.orderReasonCode(nvlToEmptyStr(orderLineIndex.getMainCreateReason()))
				.orderReasonName(nvlToEmptyStr(orderLineIndex.getMainCreateReasonName()))
				.bizFeatures(nvlToEmptyStr(orderLineIndex.getMainBizFeatures()))
				.note(nvlToEmptyStr(orderLineIndex.getMainRemark()))
				.lineNum(orderLineIndex.getSubSerialNumber())
				.sourceLineNum(orderLineIndex.getSubSourceLineNum())
				.outLineNum(orderLineIndex.getSubOuterOrderLineId())
				.shippingWarehouseCode(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseOutCode()))
				.shippingWarehouseName(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseName()))
				.deliveryFactoryCode(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryCode()))
				.deliveryFactoryName(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryName()))
				.stockCode(nvlToEmptyStr(orderLineIndex.getSubStockCode()))
				.stockName(nvlToEmptyStr(orderLineIndex.getSubStockName()))
				.innerProductCode(nvlToEmptyStr(orderLineIndex.getSubInnerProductCode()))
				.innerProductName(nvlToEmptyStr(orderLineIndex.getSubInnerProductName()))
				.productBarCode(nvlToEmptyStr(orderLineIndex.getSubProductBarCode()))
				.productCode(nvlToEmptyStr(orderLineIndex.getSubScItemOutCode()))
				.productName(nvlToEmptyStr(orderLineIndex.getSubScItemTitle()))
				.salesUnitCode(nvlToEmptyStr(orderLineIndex.getSubSaleUnitCode()))
				.salesUnitName(nvlToEmptyStr(orderLineIndex.getSubSaleUnitName()))
				.stockUnitCode(nvlToEmptyStr(orderLineIndex.getSubInventoryUnitCode()))
				.stockUnitName(nvlToEmptyStr(StockUnitEnum.of(orderLineIndex.getSubInventoryUnitCode()).getDesc()))
				.unitConversionRelationship(nvlToEmptyStr(orderLineIndex.getSubUnitConvert()))
				.stockConversionNum(nvlToEmptyStr(orderLineIndex.getSubStockConversionNum()))
				.unitPrice(StringUtils.isBlank(orderLineIndex.getSubUnitPrice()) ? "" : MoneyUtils.moneyFen2Yuan(Long.valueOf(nvlToEmptyStr(orderLineIndex.getSubUnitPrice()))))
				.totalAmount(StringUtils.isBlank(orderLineIndex.getSubShouldPayFee()) ? "" : MoneyUtils.moneyFen2Yuan(Long.valueOf(nvlToEmptyStr(orderLineIndex.getSubShouldPayFee()))))
				.manualPrice(StringUtils.isBlank(orderLineIndex.getSubShouldPayFee()) ? "" : MoneyUtils.moneyFen2Yuan(Long.valueOf(nvlToEmptyStr(orderLineIndex.getSubManualPrice()))))
				.manualTotalAmount(StringUtils.isBlank(orderLineIndex.getSubShouldPayFee()) ? "" : MoneyUtils.moneyFen2Yuan(Long.valueOf(nvlToEmptyStr(orderLineIndex.getSubManualTotalAmount()))))
				.productionDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getSubProductationTime(), DateUtils.PATTEN_YMD)))
				.productQuantity(orderLineIndex.getSubQuantity())
				.cumulativeNoticeQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeNoticeQuantity()))
				.cumulativePlanDeliveryQuantity(StringUtils.isBlank(orderLineIndex.getSubCumulativeDeliveryQuantity()) ? 0L : Long.parseLong(orderLineIndex.getSubCumulativeDeliveryQuantity()))
				.cumulativeReceivedQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeReceivedQuantity()))
				.cumulativeWaitReceivedQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeWaitOutboundQuantity()))
				.closeCode(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonCode()))
				.closeMsg(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonName()))
				.detailStatus(orderLineIndex.getSubStatus().intValue())
				.detailNote(nvlToEmptyStr(orderLineIndex.getSubRemark()))
				.detailBizFeatures(nvlToEmptyStr(orderLineIndex.getSubBizFeatures()))
				.build();
	}

	private static PageQuerySaleOrderDetailResponse convertF2B(ObtcSaleOrderLineIndex orderLineIndex) {
		JSONObject jsonObject = StringUtils.isNotBlank(orderLineIndex.getMainFeatures()) ? JSONObject.parseObject(orderLineIndex.getMainFeatures()) : new JSONObject();
		return PageQuerySaleOrderDetailResponse.builder()
				.creditCheckStatus(nvlToEmptyUtils.nvlToEmptyStr(jsonObject.get("creditCheckStatus")))
				.creditCheckStatusName(nvlToEmptyUtils.nvlToEmptyStr(jsonObject.get("creditCheckStatusName")))
				.groupCallbackMsg(orderLineIndex.getMainGroupCallbackMsg())
				.salesOrderNo(nvlToEmptyStr(orderLineIndex.getMainOrderBizId()))
				.orderCategoryCode(nvlToEmptyStr(orderLineIndex.getMainOrderCategoryCode()))
				.orderCategoryName(OrderCategoryEnum.descByCode(orderLineIndex.getMainOrderCategoryCode()))
				.orderChannelCode(nvlToEmptyStr(orderLineIndex.getMainOrderChannelCode()))
				.orderChannelName(OrderChannelEnum.descByCode(orderLineIndex.getMainOrderChannelCode()))
				.preOrderNo(nvlToEmptyStr(orderLineIndex.getMainPreOrderNo()))
				.sourceOrderNo(nvlToEmptyStr(orderLineIndex.getMainSourceOrderNo()))
				.outOrderNo(nvlToEmptyStr(orderLineIndex.getMainOuterOrderId()))
				.fromSys(nvlToEmptyStr(orderLineIndex.getMainFromSys()))
				.businessType(nvlToEmptyStr(String.valueOf(orderLineIndex.getMainBusinessType())))
				.businessTypeName(nvlToEmptyStr(orderLineIndex.getMainBusinessTypeName()))
				.businessUnitCode(nvlToEmptyStr(orderLineIndex.getMainBisUnitOutCode()))
				.businessUnitName(nvlToEmptyStr(orderLineIndex.getMainBisUnitName()))
				.salesOrderType(nvlToEmptyStr(orderLineIndex.getMainOrderType()))
				.salesOrderTypeName(nvlToEmptyStr(orderLineIndex.getMainOrderTypeName()))
				.businessChannel(nvlToEmptyStr(orderLineIndex.getMainChannelCode()))
				.businessChannelName(nvlToEmptyStr(orderLineIndex.getMainChannelName()))
				.salesOrganizationCode(nvlToEmptyStr(orderLineIndex.getMainOrganizationOutCode()))
				.salesOrganizationName(nvlToEmptyStr(orderLineIndex.getMainOrganizationName()))
				.productGroupCode(nvlToEmptyStr(orderLineIndex.getMainProductGroupCode()))
				.productGroupName(nvlToEmptyStr(orderLineIndex.getMainProductGroupName()))
				.customerCode(nvlToEmptyStr(orderLineIndex.getMainCustomerCode()))
				.customerName(nvlToEmptyStr(orderLineIndex.getMainCustomerName()))
				.shipToPartyCode(nvlToEmptyStr(orderLineIndex.getMainReceiveAddressCode()))
				.shipToPartyName(nvlToEmptyStr(orderLineIndex.getMainReceiveDetailAddress()))
				.salesChannelCode(nvlToEmptyStr(orderLineIndex.getMainSaleChannelOutCode()))
				.salesChannelName(nvlToEmptyStr(orderLineIndex.getMainSaleChannelName()))
				.salesDepartmentCode(nvlToEmptyStr(orderLineIndex.getMainDepartmentOutCode()))
				.salesDepartmentName(nvlToEmptyStr(orderLineIndex.getMainDepartmentName()))
				.customerGrade(nvlToEmptyStr(orderLineIndex.getMainCustomerGrade()))
				.customerGroup(nvlToEmptyStr(orderLineIndex.getMainCustomerGroup()))
				.costCenterCode(nvlToEmptyStr(orderLineIndex.getMainCostCenter()))
				.costCenterName(nvlToEmptyStr(orderLineIndex.getMainCostCenterName()))
				.status(nvlToEmptyStr(String.valueOf(orderLineIndex.getMainStatus())))
				.receiveStatus(nvlToEmptyStr(orderLineIndex.getMainReceiveStatus()))
				.detailReceiveStatus(nvlToEmptyStr(orderLineIndex.getSubReceiveStatus()))
				.expectedDeliveryDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerExpectDate(), DateUtils.DATE_FORMAT)))
				.deliveryMethodCode(nvlToEmptyStr(orderLineIndex.getMainTransportModeCode()))
				.deliveryMethodName(nvlToEmptyStr(orderLineIndex.getMainTransportModeName()))
				.creatorCode(nvlToEmptyStr(orderLineIndex.getMainCreatorCode()))
				.creatorName(nvlToEmptyStr(orderLineIndex.getMainCreatorName()))
				.createTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtCreate(), DateUtils.DATETIME_FORMAT)))
				.modifierCode(nvlToEmptyStr(orderLineIndex.getMainModifierCode()))
				.modifierName(nvlToEmptyStr(orderLineIndex.getMainModifierName2()))
				.modifierTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtModified(), DateUtils.DATETIME_FORMAT)))
				.customerPurchaseOrderNo(nvlToEmptyStr(orderLineIndex.getMainCustomerReferenceNo()))
				.customerPurchaseDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerPurchaseDate(), DateUtils.DATE_FORMAT)))
				.orderReasonCode(nvlToEmptyStr(orderLineIndex.getMainCreateReason()))
				.orderReasonName(nvlToEmptyStr(orderLineIndex.getMainCreateReasonName()))
				.bizFeatures(nvlToEmptyStr(orderLineIndex.getMainBizFeatures()))
				.note(nvlToEmptyStr(orderLineIndex.getMainRemark()))
				.receiveWarehouseCode(nvlToEmptyStr(orderLineIndex.getMainReceiveWareHouseOutCode()))
				.receiveWarehouseName(nvlToEmptyStr(orderLineIndex.getMainReceiveWareHouseName()))
				.receiveFactoryCode(nvlToEmptyStr(orderLineIndex.getMainReceiveFactoryCode()))
				.receiveFactoryName(nvlToEmptyStr(orderLineIndex.getMainReceiveFactoryName()))
				.receiveStockCode(nvlToEmptyStr(orderLineIndex.getSubReceiveStockCode()))
				.receiveStockName(nvlToEmptyStr(orderLineIndex.getSubReceiveStockName()))
				.shippingWarehouseCode(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseOutCode()))
				.shippingWarehouseName(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseName()))
				.deliveryFactoryCode(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryCode()))
				.deliveryFactoryName(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryName()))
				.stockCode(nvlToEmptyStr(orderLineIndex.getSubStockCode()))
				.stockName(nvlToEmptyStr(orderLineIndex.getSubStockName()))
				.lineNum(nvlToEmptyStr(orderLineIndex.getSubSerialNumber()))
				.sourceLineNum(nvlToEmptyStr(orderLineIndex.getSubSourceLineNum()))
				.outLineNum(nvlToEmptyStr(orderLineIndex.getSubOuterOrderLineId()))
				.detailStatus(nvlToEmptyStr(String.valueOf(orderLineIndex.getSubStatus())))
				.innerProductCode(nvlToEmptyStr(orderLineIndex.getSubInnerProductCode()))
				.innerProductName(nvlToEmptyStr(orderLineIndex.getSubInnerProductName()))
				.productBarCode(nvlToEmptyStr(orderLineIndex.getSubProductBarCode()))
				.productCode(nvlToEmptyStr(orderLineIndex.getSubScItemOutCode()))
				.productName(nvlToEmptyStr(orderLineIndex.getSubScItemTitle()))
				.productQuantity(nvlToEmptyStr(String.valueOf(orderLineIndex.getSubQuantity())))
				.salesUnitCode(nvlToEmptyStr(orderLineIndex.getSubSaleUnit()))
				.salesUnitName(nvlToEmptyStr(orderLineIndex.getSubSaleUnitName()))
				.stockUnitCode(nvlToEmptyStr(orderLineIndex.getSubInventoryUnitCode()))
				.stockUnitName(nvlToEmptyStr(orderLineIndex.getSubInventoryUnit()))
				.unitConversionRelationship(nvlToEmptyStr(orderLineIndex.getSubUnitConvert()))
				// .detailShippingWarehouseCode(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseCode()))
				// .detailShippingWarehouseName(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseName()))
				// .detailDeliveryFactoryCode(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryCode()))
				// .detailDeliveryFactoryName(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryName()))
				// .detailStockCode(nvlToEmptyStr(orderLineIndex.getSubStockCode()))
				// .detailStockName(nvlToEmptyStr(orderLineIndex.getSubStockName()))
				.confirmQuantity(nvlToEmptyStr(orderLineIndex.getSubConfirmQuantity()))
				.cumulativeNoticeQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeNoticeQuantity()))
				.cumulativePlanDeliveryQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeDeliveryQuantity()))
				// .deliveryQuantity(nvlToEmptyStr(orderLineIndex.getSubDeliveryAmount()))
				.proofDeliveryQuantity(nvlToEmptyStr(orderLineIndex.getSubProofDeliveryQuantity()))
				.giftQuantity(nvlToEmptyStr(orderLineIndex.getSubGiftQuantity()))
				.taxRate(nvlToEmptyStr(orderLineIndex.getSubTaxRate()))
				.productionDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getSubProductationTime(), DateUtils.PATTEN_YMD)))
				.unitPrice(StringUtils.isBlank(orderLineIndex.getSubUnitPrice()) ? "" : MoneyUtils.moneyFen2YuanStr(orderLineIndex.getSubUnitPrice()))
				.totalAmount(getTotalAmount(orderLineIndex)) // 通过常规单价计算常规总金额
				.activityPrice(StringUtils.isBlank(orderLineIndex.getSubActivityPrice()) ? "" : MoneyUtils.moneyFen2YuanStr(orderLineIndex.getSubActivityPrice()))
				.totalActivityFee(StringUtils.isBlank(orderLineIndex.getSubTotalActivityFee()) ? "" : MoneyUtils.moneyFen2YuanStr(orderLineIndex.getSubTotalActivityFee()))
				// .manualPrice(nvlToEmptyStr(orderLineIndex.getSubManualPrice()))
				// .manualTotalAmount(nvlToEmptyStr(orderLineIndex.getSubManualTotalAmount()))
				.isClose(nvlToEmptyStr(String.valueOf(orderLineIndex.getSubClosed())))
				.closeCode(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonCode()))
				.closeMsg(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonName()))
				.detailNote(nvlToEmptyStr(orderLineIndex.getSubRemark()))
				.detailBizFeatures(nvlToEmptyStr(orderLineIndex.getSubBizFeatures()))
				.relationNo(nvlToEmptyStr(orderLineIndex.getMainRelationNo()))
				.fulfillmentTypeCode(nvlToEmptyStr(orderLineIndex.getMainFulfillmentTypeCode()))
				.autoFulfillment(nvlToEmptyStr(orderLineIndex.getMainAutoFulfillment()))
				.fulfillmentPriority(nvlToEmptyStr(orderLineIndex.getMainFulfillmentPriority()))
				.orderBizTag(orderLineIndex.getMainOrderBizTag() == null ? Lists.newArrayList() : Lists.newArrayList(orderLineIndex.getMainOrderBizTag().split(",")))
				.relationLineNo(nvlToEmptyStr(orderLineIndex.getSubRelationLineNo()))
				.stockConversionNum(nvlToEmptyStr(orderLineIndex.getSubStockConversionNum()))
				.cumulativeWaitOutboundQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeWaitOutboundQuantity()))
				.cumulativeReceivedQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeReceivedQuantity()))
				.cumulativeDeliveryQuantity(nvlToEmptyStr(orderLineIndex.getSubDeliveryAmount()))
				.contact(nvlToEmptyStr(orderLineIndex.getMainContact()))
				.contactPhone(nvlToEmptyStr(orderLineIndex.getMainContactPhone()))
				.customerGroupName(orderLineIndex.getMainCustomerGroupName())
				.categoryDesc(orderLineIndex.getSubCategoryDesc())
				.categoryChildDesc(orderLineIndex.getSubCategoryChildDesc())
				.fulfillmentMsg(orderLineIndex.getSubFulfillmentMsg())
				.build();
	}

	private static PageQuerySaleOrderDetailResponse convertB2b(ObtcSaleOrderLineIndex orderLineIndex) {
		return PageQuerySaleOrderDetailResponse.builder()
				.shouldPayFee(StringUtils.isBlank(orderLineIndex.getSubShouldPayFee()) ? "" : MoneyUtils.moneyFen2YuanStr(orderLineIndex.getSubShouldPayFee()))
				.groupCallbackMsg(orderLineIndex.getMainGroupCallbackMsg())
				.orderTag(orderLineIndex.getMainOrderTag())
				.salesOrderNo(nvlToEmptyStr(orderLineIndex.getMainOrderBizId()))
				.orderCategoryCode(nvlToEmptyStr(orderLineIndex.getMainOrderCategoryCode()))
				.orderCategoryName(null)
				.orderChannelCode(nvlToEmptyStr(orderLineIndex.getMainOrderChannelCode()))
				.orderChannelName(null)
				.preOrderNo(nvlToEmptyStr(orderLineIndex.getMainPreOrderNo()))
				.sourceOrderNo(nvlToEmptyStr(orderLineIndex.getMainSourceOrderNo()))
				.outOrderNo(nvlToEmptyStr(orderLineIndex.getMainOuterOrderId()))
				.fromSys(nvlToEmptyStr(orderLineIndex.getMainFromSys()))
				.businessType(nvlToEmptyStr(String.valueOf(orderLineIndex.getMainBusinessType())))
				.businessTypeName(nvlToEmptyStr(orderLineIndex.getMainBusinessTypeName()))
				.businessUnitCode(nvlToEmptyStr(orderLineIndex.getMainBisUnitOutCode()))
				.businessUnitName(nvlToEmptyStr(orderLineIndex.getMainBisUnitName()))
				.salesOrderType(nvlToEmptyStr(orderLineIndex.getMainOrderType()))
				.salesOrderTypeName(nvlToEmptyStr(orderLineIndex.getMainOrderTypeName()))
				.businessChannel(nvlToEmptyStr(orderLineIndex.getMainChannelCode()))
				.businessChannelName(nvlToEmptyStr(orderLineIndex.getMainChannelName()))
				.salesOrganizationCode(nvlToEmptyStr(orderLineIndex.getMainOrganizationOutCode()))
				.salesOrganizationName(nvlToEmptyStr(orderLineIndex.getMainOrganizationName()))
				.productGroupCode(nvlToEmptyStr(orderLineIndex.getMainProductGroupCode()))
				.productGroupName(nvlToEmptyStr(orderLineIndex.getMainProductGroupName()))
				.customerCode(nvlToEmptyStr(orderLineIndex.getMainCustomerCode()))
				.customerName(nvlToEmptyStr(orderLineIndex.getMainCustomerName()))
				.shipToPartyCode(nvlToEmptyStr(orderLineIndex.getMainReceiveAddressCode()))
				.shipToPartyName(nvlToEmptyStr(orderLineIndex.getMainReceiveDetailAddress()))
				.salesChannelCode(nvlToEmptyStr(orderLineIndex.getMainSaleChannelOutCode()))
				.salesChannelName(nvlToEmptyStr(orderLineIndex.getMainSaleChannelName()))
				.salesDepartmentCode(nvlToEmptyStr(orderLineIndex.getMainDepartmentOutCode()))
				.salesDepartmentName(nvlToEmptyStr(orderLineIndex.getMainDepartmentName()))
				.customerGrade(null)
				.customerGroup(null)
				.costCenterCode(nvlToEmptyStr(orderLineIndex.getMainCostCenter()))
				.costCenterName(nvlToEmptyStr(orderLineIndex.getMainCostCenterName()))
				.status(nvlToEmptyStr(String.valueOf(orderLineIndex.getMainStatus())))
				.receiveStatus(null)
				.detailReceiveStatus(null)
				.expectedDeliveryDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerExpectDate(),DateUtils.DATE_FORMAT)))
				.deliveryMethodCode(nvlToEmptyStr(orderLineIndex.getMainTransportModeCode()))
				.deliveryMethodName(nvlToEmptyStr(orderLineIndex.getMainTransportModeName()))
				.creatorCode(nvlToEmptyStr(orderLineIndex.getMainCreatorCode()))
				.creatorName(nvlToEmptyStr(orderLineIndex.getMainCreatorName()))
				.createTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtCreate(), DateUtils.DATETIME_FORMAT)))
				.modifierCode(nvlToEmptyStr(orderLineIndex.getMainModifierCode()))
				.modifierName(nvlToEmptyStr(orderLineIndex.getMainModifierName2()))
				.modifierTime(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainGmtModified(), DateUtils.DATETIME_FORMAT)))
				.customerPurchaseOrderNo(nvlToEmptyStr(orderLineIndex.getMainCustomerReferenceNo()))
				.customerPurchaseDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getMainCustomerPurchaseDate(),DateUtils.DATE_FORMAT)))
				.orderReasonCode(nvlToEmptyStr(orderLineIndex.getMainCreateReason()))
				.orderReasonName(nvlToEmptyStr(orderLineIndex.getMainCreateReasonName()))
				.bizFeatures(nvlToEmptyStr(orderLineIndex.getMainBizFeatures()))
				.note(nvlToEmptyStr(orderLineIndex.getMainRemark()))
				.receiveWarehouseCode(null)
				.receiveWarehouseName(null)
				.receiveFactoryCode(null)
				.receiveFactoryName(null)
				.receiveStockCode(null)
				.receiveStockName(null)
				.shippingWarehouseCode(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseOutCode()))
				.shippingWarehouseName(nvlToEmptyStr(orderLineIndex.getSubShippingWarehouseName()))
				.deliveryFactoryCode(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryCode()))
				.deliveryFactoryName(nvlToEmptyStr(orderLineIndex.getSubDeliveryFactoryName()))
				.stockCode(nvlToEmptyStr(orderLineIndex.getSubStockCode()))
				.stockName(nvlToEmptyStr(orderLineIndex.getSubStockName()))
				.lineNum(nvlToEmptyStr(orderLineIndex.getSubSerialNumber()))
				.sourceLineNum(nvlToEmptyStr(orderLineIndex.getSubSourceLineNum()))
				.outLineNum(nvlToEmptyStr(orderLineIndex.getSubOuterOrderLineId()))
				.detailStatus(nvlToEmptyStr(String.valueOf(orderLineIndex.getSubStatus())))
				.innerProductCode(nvlToEmptyStr(orderLineIndex.getSubInnerProductCode()))
				.innerProductName(nvlToEmptyStr(orderLineIndex.getSubInnerProductName()))
				.productBarCode(nvlToEmptyStr(orderLineIndex.getSubProductBarCode()))
				.productCode(nvlToEmptyStr(orderLineIndex.getSubScItemOutCode()))
				.productName(nvlToEmptyStr(orderLineIndex.getSubScItemTitle()))
				.productQuantity(nvlToEmptyStr(String.valueOf(orderLineIndex.getSubQuantity())))
				.salesUnitCode(nvlToEmptyStr(orderLineIndex.getSubSaleUnit()))
				.salesUnitName(nvlToEmptyStr(orderLineIndex.getSubSaleUnitName()))
				.stockUnitCode(nvlToEmptyStr(orderLineIndex.getSubInventoryUnitCode()))
				.stockUnitName(nvlToEmptyStr(orderLineIndex.getSubInventoryUnit()))
				.unitConversionRelationship(nvlToEmptyStr(orderLineIndex.getSubUnitConvert()))
				.confirmQuantity(nvlToEmptyStr(orderLineIndex.getSubConfirmQuantity()))
				.cumulativeNoticeQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeNoticeQuantity()))
				.cumulativePlanDeliveryQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeDeliveryQuantity()))
				.giftQuantity(null)
				.taxRate(null)
				.productionDate(nvlToEmptyStr(DateUtils.toDateStr(orderLineIndex.getSubProductationTime(), DateUtils.PATTEN_YMD)))
				.unitPrice(StringUtils.isBlank(orderLineIndex.getSubUnitPrice()) ? "" : MoneyUtils.moneyFen2Yuan(Long.valueOf(orderLineIndex.getSubUnitPrice())))
				.totalAmount(getTotalAmount(orderLineIndex)) // 通过常规单价计算常规总金额
				.activityPrice(nvlToEmptyStr(orderLineIndex.getSubActivityPrice()))
				.totalActivityFee(nvlToEmptyStr(orderLineIndex.getSubTotalActivityFee()))
				.isClose(nvlToEmptyStr(String.valueOf(orderLineIndex.getSubClosed())))
				.closeCode(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonCode()))
				.closeMsg(nvlToEmptyStr(orderLineIndex.getSubRefuseReasonName()))
				.detailNote(nvlToEmptyStr(orderLineIndex.getSubRemark()))
				.detailBizFeatures(nvlToEmptyStr(orderLineIndex.getSubBizFeatures()))
				.relationNo(nvlToEmptyStr(orderLineIndex.getMainRelationNo()))
				.fulfillmentTypeCode(nvlToEmptyStr(orderLineIndex.getMainFulfillmentTypeCode()))
				.autoFulfillment(nvlToEmptyStr(orderLineIndex.getMainAutoFulfillment()))
				.fulfillmentPriority(nvlToEmptyStr(orderLineIndex.getMainFulfillmentPriority()))
				.orderBizTag(orderLineIndex.getMainOrderBizTag() == null ? Lists.newArrayList() : Lists.newArrayList(orderLineIndex.getMainOrderBizTag().split(",")))
				.relationLineNo(nvlToEmptyStr(orderLineIndex.getSubRelationLineNo()))
				.stockConversionNum(nvlToEmptyStr(orderLineIndex.getSubStockConversionNum()))
				.cumulativeWaitOutboundQuantity(nvlToEmptyStr(orderLineIndex.getSubCumulativeWaitOutboundQuantity()))
				.cumulativeReceivedQuantity(null)
				.cumulativeDeliveryQuantity(nvlToEmptyStr(orderLineIndex.getSubDeliveryAmount()))
				.contact(nvlToEmptyStr(orderLineIndex.getMainContact()))
				.contactPhone(nvlToEmptyStr(orderLineIndex.getMainContactPhone()))
				.kaSystem(nvlToEmptyStr(orderLineIndex.getMainKaSystem()))
				.kaArea(nvlToEmptyStr(orderLineIndex.getMainKaArea()))
				.cashCustomerName(nvlToEmptyStr(orderLineIndex.getMainCashCustomerName()))
				.sourceTime(nvlToEmptyStr(orderLineIndex.getMainSourceDate()))
				.sourceUnit(nvlToEmptyStr(orderLineIndex.getSubSourceUnit()))
				.sourceQuantity(nvlToEmptyStr(orderLineIndex.getSubSourceQuantity()))
				.sourcePrice(nvlToEmptyStr(orderLineIndex.getSubSourcePrice()))
				.activityType(nvlToEmptyStr(orderLineIndex.getSubActivityType()))
				.activityId(nvlToEmptyStr(orderLineIndex.getSubActivityCode()))
				.activityName(nvlToEmptyStr(orderLineIndex.getSubActivityName()))
				.activityLineNo(nvlToEmptyStr(orderLineIndex.getSubActivityLineNo()))
				.giftFlag(nvlToEmptyStr(orderLineIndex.getSubGiftFlag()))
				.buyItemNo(nvlToEmptyStr(orderLineIndex.getSubBuyItemNo()))
				.manualPrice(nvlToEmptyStr(orderLineIndex.getSubManualPrice()))
				.manualTotalAmount(nvlToEmptyStr(orderLineIndex.getSubManualTotalAmount()))
				.customerGroup(nvlToEmptyStr(orderLineIndex.getMainCustomerGroup()))
				.customerGroupName(nvlToEmptyStr(orderLineIndex.getMainCustomerGroupName()))
				.categoryDesc(orderLineIndex.getSubCategoryDesc())
				.categoryChildDesc(orderLineIndex.getSubCategoryChildDesc())
				.activityName(nvlToEmptyStr(orderLineIndex.getSubActivityName()))
				.invoiceNo(nvlToEmptyStr(orderLineIndex.getSubInvoiceNo()))
				.invoiceLineNo(nvlToEmptyStr(orderLineIndex.getSubInvoiceLineNo()))
				.proofDeliveryQuantity(nvlToEmptyStr(orderLineIndex.getSubPodQty()))
				.build();
	}

	/**
	 * 字段值如果为空，返回空字符串，而不是null。
	 */
	private static String nvlToEmptyStr(String source) {
        return nvlToEmptyUtils.nvlToEmptyStr(source);
	}

	private static String getTotalAmount(ObtcSaleOrderLineIndex orderLineIndex) {
		// 由于带活动的订单shouldPayFee字段会被刷成活动后总金额，所以常规总金额改为通过常规单价计算
		try {
			String unitPrice = StringUtils.isNotBlank(orderLineIndex.getSubUnitPrice()) ? orderLineIndex.getSubUnitPrice() : "0";
			BigDecimal totalAmount = new BigDecimal(unitPrice).multiply(BigDecimal.valueOf(orderLineIndex.getSubQuantity()));
			return MoneyUtils.moneyFen2Yuan(String.valueOf(totalAmount));
		} catch (Exception e) {
			log.error("ObtcSaleOrderLineIndexToResponseConvertor#getTotalAmount error", e);
		}
		return "";
	}
}
